﻿/*
     多文件上传
*/
CKEDITOR.dialog.add('MultilFileUpLoad', function (editor) {
    function GetURL() {
        return "/js/ckeditor/plugins/MultilFileUpLoad/SWFUpload/Default.aspx?MultilFileUpLoad_Random=" + Math.random();
    }
    return {
        title: "批量上传",
        minWidth: 502,
        minHeight: 550,
        onShow: function () {
            var element = this.getParentEditor().getSelection().getSelectedElement();
            this.setupContent(element);
            this.getElement().getHtml().replace("MultilFileUpLoad_Random=", "MultilFileUpLoad_Random=" + Math.random());
            //alert("show");
            //
            //this.parts.contents.$.innerHTML = this.parts.contents.$.innerHTML.toString().replace("=MathRound", "=" + Math.random());
        },
        onOk: function () {
            editor = this.getParentEditor();
            element = CKEDITOR.dom.element.createFromHtml('<p></p>');
            this.commitContent(element);
            editor.insertElement(element);
        },
        contents: [
			{
			    id: 'tab1',
			    label: '',
			    title: '',
			    expand: true,
			    padding: 0,
			    elements:
				[
                    {
                        type: 'html',
                        html: '<input type="hidden"  id="MultilFileUpLoad_hiddenFiles_values"  name="MultilFileUpLoad_hiddenFiles_values" value="" />' +
							'<div style="height: 560px; width:520px;" >' +
                                '<iframe id="MutifileUploads_mainframe"  style="height: 560px; width:520px;" scrolling="auto" src="' + GetURL() + '" ></iframe>' +
							'</div>',
                        commit: function (element) {
                            var strAllFiles = this._.dialog.getElement().getDocument().getById("MultilFileUpLoad_hiddenFiles_values").$.value.split("|");
                            var strHtml = "";
                            strHtml += '';
                            for (i = 0; i < strAllFiles.length; i++) {
                                if (strAllFiles[i] != "" && strAllFiles[i].indexOf(".") > 0) {
                                    if (strAllFiles[i].toString().indexOf("×") > 0 && strAllFiles[i].toString().indexOf("_") > 0) {

                                        strHtml += '<a  target="_blank"  href="[@GetHttpURLForLocalFile(\'' +
                                                           strAllFiles[i].toString().substring(0, strAllFiles[i].toString().indexOf("_")) + strAllFiles[i].toString().substring(strAllFiles[i].toString().indexOf("."))
                                                    + '\')]" border="0" title="点击查看原图" >';
                                        strHtml += '<img alt="" border="0" src="' + strAllFiles[i] + '" />';
                                        strHtml += '</a>';
                                    }
                                    else {
                                        strHtml += '<img alt="" src="' + strAllFiles[i] + '" />';
                                    }
                                    strHtml += '&nbsp;&nbsp;';
                                }
                            }
                            if (strHtml != '') {
                                strHtml = strHtml.substring(0, strHtml.lastIndexOf("&nbsp;&nbsp;"));
                            }
                            strHtml += '';
                            element.$.innerHTML = strHtml;
                            this._.dialog.getElement().getDocument().getById("MultilFileUpLoad_hiddenFiles_values").$.value = "";
                            this._.dialog.getElement().getDocument().getById("MutifileUploads_mainframe").$.contentDocument.location.href = '/js/ckeditor/plugins/MultilFileUpLoad/SWFUpload/Default.aspx?random=' + Math.random();
                        }
                    }
				]
			}
		],
        buttons: [CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton]
    };
});
